/*
 * DeviceProtocol.h
 *
 *  Created on: Dec 8, 2011
 *      Author: kylintse
 */

#ifndef DEVICEPROTOCOL_H_
#define DEVICEPROTOCOL_H_

#include <QtCore>

#include "kthread.h"
#include "KjDevice.h"

class DeviceProtocol
{
public:
	DeviceProtocol(quint32 id,const QString& devNode,KjDeviceList* lstDevice);
	virtual ~DeviceProtocol();

public:
	quint32 getId(){return m_id;}

	virtual bool start()=0;
	virtual void stop()=0;

	virtual void recycle()=0;

protected:
	quint32 m_id;
	QString m_devNode;
	KjDeviceList* m_lstDevice;
};

class DeviceProtocolRecycler : public kthread
{
public:
	DeviceProtocolRecycler(DeviceProtocol* protocol,QObject* parent=0);
	~DeviceProtocolRecycler();

protected:
	virtual void run();

private:
	DeviceProtocol* m_protocol;
};

class DeviceProtocolManager
{
public:
	DeviceProtocolManager(KjDeviceList* lstDevice);
	virtual ~DeviceProtocolManager();

public:
	bool startProtocol();

private:
	KjDeviceList* m_lstDevice;
	QMap<quint32,DeviceProtocol*> m_protocols;
};

#endif /* DEVICEPROTOCOL_H_ */
